import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import AutoImport from "unplugin-auto-import/vite";
import path from 'node:path'; //node内置模块无需下载直接使用
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ["vue"],
      eslintrc: {
        enabled: false, // 是否自动生成 eslint 规则，建议生成之后设置 false 
        filepath: "./.eslintrc-auto-import.json", // 指定自动导入函数 eslint 规则的文件
       },
      dts: path.resolve(fileURLToPath(new URL('./src', import.meta.url)), "types", "auto-imports.d.ts"), // 指定自动导入函数TS类型声明文件路径
      resolvers: [ElementPlusResolver()], // 自动导入 ElementPlus 组件
  }),
    vueDevTools(),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server:{
    proxy: {
      // 选项写法
      '/api': {
        target: 'https://v4.fenxi365.com',
        // target: 'https://v4.fenxi365.com/api',
        // target: 'https://x.dscmall.cn/api',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    }
  }
})
